package com.mm.cloud.sys.controller;


import com.mm.cloud.common.core.result.Result;
import com.mm.cloud.common.security.annotation.PreAuthorize;
import com.mm.cloud.sys.dto.form.DictItemDTO;
import com.mm.cloud.sys.service.IDictItemService;
import com.mm.cloud.sys.vo.DictItemVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典数据 前端控制器
 * </p>
 *
 * @author mr
 * @since 2022-11-12
 */
@Tag(name = "字典数据")
@RestController
@AllArgsConstructor
@RequestMapping("/sys/dictItem")
public class DictItemController {

    /**
     * 字典数据
     */
    private final IDictItemService dictItemService;

    @Operation(summary = "列表查询【mr】", description = "列表查询")
    @PostMapping("/getDictItemList/{dictTypeId}")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_ITEM_LIST")
    public Result<List<DictItemVO>> getDictItemList(@PathVariable("dictTypeId") Long dictTypeId) {
        return dictItemService.getDictItemList(dictTypeId);
    }

    @Operation(summary = "新增字典数据【mr】", description = "新增字典数据")
    @PostMapping("/saveDictItem")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_ITEM_ADD")
    public Result<String> saveDictItem(@RequestBody DictItemDTO dto) {
        return dictItemService.saveDictItem(dto);
    }

    @Operation(summary = "修改字典数据【mr】", description = "修改字典数据")
    @PostMapping("/updateDictItem")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_ITEM_EDIT")
    public Result<String> updateDictItem(@RequestBody DictItemDTO dto) {
        return dictItemService.updateDictItem(dto);
    }

    @Operation(summary = "删除字典数据【mr】", description = "删除字典数据")
    @PostMapping("/deleteDictItem/{dictItemId}")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_ITEM_DELETE")
    public Result<String> deleteDictItem(@PathVariable("dictItemId") Long dictItemId) {
        return dictItemService.deleteDictItem(dictItemId);
    }

}

